#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10;
int st1[N], st2[N], tt1 = 0, tt2 = 0;
int a[N];
int n, T;

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &T);
    while(T -- )
    {
        scanf("%d", &n);
        for(int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
        int maxv = 0;
        memset(st1, 0, sizeof st1);
        memset(st2, 0, sizeof st2);
        for(int i = 0; i < 1 << n; i ++ )
        {
            int res = 0;
            tt1 = tt2 = 0;
            st1[0] = st2[0] = 0;
            for(int j = 0; j < n; j ++ )
            {
                if(i >> j & 1)
                {
                    if(a[j] == st1[tt1]) 
                    {
                        res += a[j];
                    }
                    st1[++ tt1] = a[j];
                }
                else
                {
                    if(a[j] == st2[tt2])
                    {
                        res += a[j];
                    }
                    st2[++ tt2] = a[j];
                }
            }
            maxv = max(maxv, res);
        }
        printf("%d\n", maxv);
    }
}
